package cn.lixu.controller;

import cn.lixu.domain.User;
import cn.lixu.feign.UserFeignClient;
import cn.lixu.sentne.FuseDowngradeUtil;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiXu
 * @date 2022/08/23 0023 18:01:54
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserFeignClient userFeignClient;


    @Value("${server.port}")
    private String port;

    //提供一个根据Id返回User对象的接口，给order服务调用
    @GetMapping("/getById/{id}")
    // @SentinelResource(value = "order-service", fallback = "orderFallback", fallbackClass = FuseDowngradeUtil.class)
    public User getById(@PathVariable("id") Long id) {
        return userFeignClient.getById(id);
    }


    public User orderFallback(@PathVariable("id") Long id, Throwable e) {

        e.printStackTrace();
        return new User(-1L, "服务被熔断", "您的服务被熔断，请稍候再试");
    }
}
